package com.example.first_examination.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.first_examination.Bean.DatasBean;
import com.example.first_examination.R;

import java.util.ArrayList;

public class MyAdapter extends RecyclerView.Adapter {

    private Context context;
    private ArrayList<DatasBean> list;

    public MyAdapter(Context context, ArrayList<DatasBean> list) {
        this.context = context;
        this.list = list;
    }
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_item, parent, false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ViewHolder holder1 = (ViewHolder) holder;
        holder1.tv_niceData.setText(list.get(position).getNiceDate());
        holder1.tv_shareDate.setText(list.get(position).getShareDate()+"");
        holder1.tv_superChapterName.setText(list.get(position).getSuperChapterName());
        holder1.tv_title.setText(list.get(position).getTitle());
        holder1.iv_envelopePic.setImageResource(R.drawable.heart_select);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static
    class ViewHolder extends RecyclerView.ViewHolder {
        public View rootView;
        public TextView tv_shareDate;
        public TextView tv_niceData;
        public TextView tv_title;
        public TextView tv_superChapterName;
        public ImageView iv_envelopePic;

        public ViewHolder(View rootView) {
            super(rootView);
            this.rootView = rootView;
            this.tv_shareDate = (TextView) rootView.findViewById(R.id.tv_shareDate);
            this.tv_niceData = (TextView) rootView.findViewById(R.id.tv_niceData);
            this.tv_title = (TextView) rootView.findViewById(R.id.tv_title);
            this.tv_superChapterName = (TextView) rootView.findViewById(R.id.tv_superChapterName);
            this.iv_envelopePic = (ImageView) rootView.findViewById(R.id.iv_envelopePic);
        }

    }
}
